//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import gridFooter from "./box/CabinetBox.vue";
import gridHeader from "./box/boxInfo.vue";
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader:gridHeader,//{ template: "<div>扩展组xx件</div>" },
        gridBody: '',
        gridFooter: gridFooter,
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: {view: [], box:[],  detail:[]},//扩展的按钮
    methods: {//事件扩展
        getFormOption(field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                })
            })
            return option;
        },
       onInit() {
        var selectOption = this.getFormOption('cabinetType');
        selectOption.onChange = (val, item) => {
          this.$refs.detail.$refs.table.tableData.splice(0,this.$refs.detail.$refs.table.tableData.length);
          if(val){
            this.http.get(`api/Cabinet/getcabinetType?type=${val}`)
            .then(result => {
                this.$refs.detail.$refs.table.tableData.push(...result.data)
            })
          }
        }
        this.columns.push({
          title: '操作', width: 165,fixed: 'right', render: (h, { row, column, index }) => {
            return h(
              "div",
              { style: {} },
              [
                h(
                  "Button",
                  {
                    props: { type: "success", size: "small" },
                    style: {},
                    on: {
                      click: (e) => {
                        this.$refs.gridHeader.open1(row)
                      }
                    }
                  },
                  "柜组状态"
                )
              ]
            );
          }
        })
       },
       rowClick({ row, column, event }) { //查询界面table点击行选中当前行
        //console.log(row,column,event);
        let where = {
          sort:"id",
          value:row.id,
          };

        this.$refs.table.$refs.table.toggleRowSelection(row);
        this.$refs.gridFooter.$refs.tableList.load(where)
        if(this.$refs.table.getSelected().length>1){
          this.$refs.gridFooter.$refs.tableList.reset()
        }
        return true;
       },
       searchAfter(rows) {
        //页面加载或者刷新数据后直接显示第一行的明细
        if (rows.length) {
          let where = {wheres:[
            {"name":"id","value":rows[0].id,displayType:"text"},
          //设置为like模糊查询
            ]};
          // this.$nextTick(() => {
          this.$refs.gridFooter.$refs.tableList.load(where)
          // })
         }else{
          //没有数据时，清空明细数据
          this.$refs.gridFooter.$refs.tableList.reset()
        }
        
        return true;

      },
    }
};
export default extension;